package values.item
{
import mx.utils.StringUtil;

public class ItemRequirementValue
{
	private static const XML_PATTERN:String = "<requirements>" +
												"<level_required>{0}</level_required>" +
                                                "<city_level_required>{1}</city_level_required>" +
                                                "<quest_required>{2}</quest_required>" +
										      "</requirements>"
	
	public function ItemRequirementValue()
	{
	}
	
	[Data(type="field", mapping="level_required")]
	public var levelRequired:int = 1;
    
    [Data(type="field", mapping="city_level_required")]
    public var cityLevelRequired:int = 1;
    
    [Data(type="field", mapping="quest_required")]
    public var questRequired:String = "'";
	
	private var _owner:ItemTemplateValue
	
	public function get owner():ItemTemplateValue
	{
		return _owner;
	}
	
	[Data(type="mapping",  way="belong")]
	public function set owner(value:ItemTemplateValue):void
	{
		_owner = value;
	}
	
	public function clone():ItemRequirementValue
	{
		var vo:ItemRequirementValue = new ItemRequirementValue();
		vo.levelRequired = levelRequired;
		vo.cityLevelRequired = cityLevelRequired;
        vo.questRequired = questRequired;
		vo.owner = owner;
		return vo;
	}
	
	public function generateXML():XML
	{
		var xmlStr:String = StringUtil.substitute(XML_PATTERN, 
												  this.levelRequired,
												  this.cityLevelRequired,
                                                  this.questRequired);
		return new XML(xmlStr);
	}
}
}



